/**
 * 
 */
package examples.rulesets;

import framework.interfaces.Cell;
import framework.interfaces.RuleSet;
import framework.world.Direction;

/**
 * An example RuleSet plugin that sets up a Wireworld simulation with a blank
 * grid.
 */
public class Wireworld implements RuleSet{

	//States
	private final static int INSULATION = 0;
	private final static int WIRE = 1;
	private final static int ELEC_HEAD = 2;
	private final static int ELEC_TAIL = 3;
	
	@Override
	public int getNextState(Cell active) {
		if(active.getState() == INSULATION){
			return INSULATION;
		}
		if(active.getState() == ELEC_HEAD){
			return ELEC_TAIL;
		}
		if(active.getState() == ELEC_TAIL){
			return WIRE;
		}
		int numNeighborHeads = active.getNeighborCount(ELEC_HEAD);
		if(active.getState() == WIRE && (numNeighborHeads == 1 ||
										 numNeighborHeads == 2)){
			return ELEC_HEAD;
		}
		
		//Added here to increase code coverage
		active.setMachineState(active.getMachineState());
		active.getAdjacentCellState(Direction.E);
		//End code coverage increasing code
		
		//All other cases are caught, so the only possibility left is to be a wire
		return WIRE;
	}

	@Override
	public boolean getToroidal() {
		return true;
	}

	@Override
	public int getGridRows() {
		// TODO Auto-generated method stub
		return 60;
	}

	@Override
	public int getGridCols() {
		// TODO Auto-generated method stub
		return 60;
	}

	@Override
	public int getNeighborhoodSize() {
		// TODO Auto-generated method stub
		return 8;
	}

	@Override
	public int getNumStates() {
		// TODO Auto-generated method stub
		return 4;
	}

	@Override
	public int getDefaultState() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int[][] getStartingGrid() {
		return null;
	}

	@Override
	public int getStartingMachineState() {
		return 0;
	}

	@Override
	public String[] getStateNames() {
		String[] output = {"Insulation", "Wire", "Head", "Tail"};
		
		return output;
	}

}
